package com.skzh.web.controller.equipment;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.skzh.common.core.domain.model.LoginUser;
import com.skzh.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.skzh.common.annotation.Log;
import io.swagger.annotations.ApiOperation;
import com.skzh.common.core.controller.BaseController;
import com.skzh.common.core.domain.AjaxResult;
import com.skzh.common.enums.BusinessType;
import com.skzh.equipment.domain.Dock;
import com.skzh.equipment.service.IDockService;
import com.skzh.common.utils.poi.ExcelUtil;
import com.skzh.common.core.page.TableDataInfo;

/**
 * 机场基本信息Controller
 *
 * @author skzh
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/equipment/dock_info")
public class DockController extends BaseController {
    @Autowired
    private IDockService dockService;

    /**
     * 查询机场基本信息列表
     */
    @ApiOperation(value = "查询机场基本信息列表")
    @PreAuthorize("@ss.hasPermi('equipment:dock_info:list')")
    @GetMapping("/list" )
    public TableDataInfo list(Dock dock) {
        startPage();
        List<Dock> list = dockService.selectDockList(dock);
        return getDataTable(list);
    }

    /**
     * 导出机场基本信息列表
     */
    @ApiOperation(value = "导出机场基本信息列表")
    @PreAuthorize("@ss.hasPermi('equipment:dock_info:export')" )
    @Log(title = "机场基本信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, Dock dock) {
        List<Dock> list = dockService.selectDockList(dock);
        ExcelUtil<Dock> util = new ExcelUtil<Dock>(Dock. class);
        util.exportExcel(response, list, "机场基本信息数据" );
    }

    /**
     * 获取机场基本信息详细信息
     */
    @ApiOperation(value = "获取机场基本信息详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:dock_info:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(dockService.selectDockById(id));
    }

    /**
     * 新增机场基本信息
     */
    @ApiOperation(value = "新增机场基本信息")
    @PreAuthorize("@ss.hasPermi('equipment:dock_info:add')" )
    @Log(title = "机场基本信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dock dock) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        dock.setCreateBy(loginUser.getUsername());
        return toAjax(dockService.insertDock(dock));
    }

    /**
     * 修改机场基本信息
     */
    @ApiOperation(value = "修改机场基本信息")
    @PreAuthorize("@ss.hasPermi('equipment:dock_info:edit')" )
    @Log(title = "机场基本信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dock dock) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        dock.setUpdateBy(loginUser.getUsername());
        return toAjax(dockService.updateDock(dock));
    }

    /**
     * 删除机场基本信息
     */
    @ApiOperation(value = "删除机场基本信息")
    @PreAuthorize("@ss.hasPermi('equipment:dock_info:remove')" )
    @Log(title = "机场基本信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dockService.deleteDockByIds(ids));
    }

    /**
     * 查询所有未绑定的机场名称
     */
    @ApiOperation(value = "查询所有未绑定的机场名称")
    @PreAuthorize("@ss.hasPermi('equipment:dock_info:no_bind')" )
    @GetMapping("/allNoBind" )
    public List<Map<String, Object>> getAllNoBind() {
        return dockService.selectAllNoBind();
    }

    /**
     * 获取在线设备列表
     */
    @ApiOperation(value = "获取在线设备列表")
    @GetMapping("/onlineDevices")
    public TableDataInfo getOnlineDevices(Dock dock) {
        startPage();
        List<Map<String, Object>> list = dockService.selectOnlineDevicesList(dock);
        return getDataTable(list);
    }
}
